// nxtremote.cpp : main project file.

#include <string>
#include <iostream>
#include "bluetooth.h"
#include "motor.h"
#include <conio.h>

int detect_bt_devices();

int main(int argc, char* argv[])
{
   //detect_bt_devices();

   Bluetooth bt;
   bt.connect(12);

   std::cout << "Connected" << std::endl;

   //std::cout << "Run program, then press enter" << std::endl;
   //getch();

	//Motor m(OUT_B,&bt);
	//m.on(100);
	//Sleep(2000);
	//m.off();

    char msg[] = "Hello BT";
	bt.send((unsigned char *)msg, strlen(msg));

   // Give NXT a chance to switch form receive to send mode...
   // seen here: http://www.mindstorms.rwth-aachen.de/documents/downloads/doc/version-4.03/pc_nxt_communication.html#14

   while (true)
   {
      try
      {
         Sleep(30);
         unsigned char receiveBuffer[256];
         bt.receive(receiveBuffer, 1);
         std::cout << "Received: " << receiveBuffer << std::endl;
      }
      catch (exception e)
      {}
   }

	//Sleep(5000);

   //for(int i=0; i<42; ++i)
   //{
   //   unsigned char msg2[] = {0,0};
   //   bt.send(msg2, 2);
   //   Sleep(500);
   //}

	bt.disconnect();

    return 0;
}